<?php
require_once('classes/settings.php');
require_once('classes/search.php');
require_once('classes/tickets.php');
require_once('classes/resultHandler.php');
require_once('classes/filter.php');
require_once('classes/pagination.php');
require_once('classes/database.php');


$db = new Database(); 
$db->connectToDB();

session_start();

$ticket = $_SESSION['allTickets'][$_GET['id']];
#$deptStops = $ticket->outboundStops;

?>


<img id="closeDetailsImg" style="display:block;" src="images/close.png" alt="close Details"/>
<div id="bookingPanelContainer">



    <div class="detailsBox">
        <h3>Reisdetails</h3>
        <div class="detailsHeader">
            <div class="zoekopdracht">
                <div class="flightDept">
                    <img src="images/flightDetailsPlane.jpg" class="flightDetailsimg"/>
                    <span class="flightHeader">Heenreis: <?php echo $_SESSION['search']->getDepartureDate(); ?></span>
                </div>

                <!-- IF RETURN -->
                <?php if ($_SESSION['search']->getReturnDate() != "") { ?>
                    <div class="flightRet">
                        <img src="images/flightDetailsPlaneBack.jpg" class="flightDetailsimgBack"/>
                        <span class="flightHeaderBack">Terugreis: <?php echo $_SESSION['search']->getReturnDate(); ?></span>
                    </div>
                <?php } else { ?>
                    <div class="flightRet">
                        <img src="images/flightDetailsPlaneBack.jpg" class="flightDetailsimgBack"/>
                        <span class="flightHeaderBack">Er is geen terugreis</span>
                    </div>
                <?php } ?>
            </div>
        </div>
        <div class="detailsBoxInfo">
            <div class="shortInfo">
                <div id="leftColumn">
                    <?php
                    $outbound = $ticket->flights_outbound;

                    for ($x = 0; $x <= $ticket->outboundStops;) {

                        if ($x > 0) {
                            echo '<div class="overstappen">Overstappen op vliegveld</div>';
                        }

                        echo '<div class="connector"><img src="images/connector.jpg" alt="connector"></div>';
                        echo '<div class="vertrek">
                                        Vertrek
                                        <span class="vertrektijd">' . $outbound["$x"]['fromDateTime']->format("h:i") . '</span>
                                        <span class="vliegveld">' . $db->getCity($outbound["$x"]['fromIATA']) . ' (' . $outbound["$x"]['fromIATA'] . ')</span>
                                  </div>
                                  <div class="flightnumber">' . $outbound["$x"]['flightNumber'] . '</div>

                                  <div class="aankomst">
                                        Aankomst
                                        <span class="aankomsttijd" >' . $outbound["$x"]['toDateTime']->format("h:i") . '  </span>
                                        <span class="vliegveld">' . $db->getCity($outbound["$x"]['toIATA']) . ' (' . $outbound["$x"]['toIATA'] . ')</span>
                                  </div>
                                  <div class="flightnumber">' . $outbound["$x"]['carrier'] . '</div>';
                        $x++;
                    }
                    echo '<br/>
                              <div class="vliegtijd">
                                  <b>Vliegtijd:</b>
                                  <span class="vliegtijden" >' . $ticket->journeyTime . 'uur </span>
                              </div>';
                    ?>
                </div>
                <div id="rightColumn">
                    <?php
                    if ($ticket->inboundStops > 0) {
                        $inbound = $ticket->flights_inbound;

                        for ($x = 0; $x < $ticket->inboundStops;) {

                            if ($x > 0) {
                                echo '<div class="overstappen">Overstappen op vliegveld</div>';
                            }

                            echo '<div class="connector"><img src="images/connector.jpg" alt="connector"></div>';
                            echo '<div class="vertrek">
                                        Vertrek
                                        <span class="vertrektijd">' . $inbound["$x"]['fromDateTime']->format("h:i") . '</span>
                                        <span class="vliegveld">' . $db->getCity($inbound["$x"]['fromIATA']) . ' (' . $inbound["$x"]['fromIATA'] . ')</span>
                                  </div>
                                  <div class="flightnumber">' . $inbound["$x"]['flightNumber'] . '</div>

                                  <div class="aankomst">
                                        Aankomst
                                        <span class="aankomsttijd" >' . $inbound["$x"]['toDateTime']->format("h:i") . '  </span>
                                        <span class="vliegveld">' . $db->getCity($inbound["$x"]['toIATA']) . ' (' . $inbound["$x"]['toIATA'] . ')</span>
                                  </div>
                                  <div class="flightnumber">' . $inbound["$x"]['carrier'] . '</div>';
                            $x++;
                        }
                        echo '<br/>
                              <div class="vliegtijd">
                                  <b>Vliegtijd:</b>
                                  <span class="vliegtijden" >' . $ticket->journeyTime . 'uur </span>
                              </div>';
                    }
                        ?>

                    </div>
                    <br class="clear"/>
                </div>

            </div>

        </div><br class="clear"/>
        <div class="detailsFooter">

            <h3 class="boeknu">Boek nu direct - Goedkope-Vliegtickets.nl rekent geen extra kosten! </h3>
            <a class="booklink" href="<?php echo $_SESSION['allTickets'][$id]['url']; ?>"><button width="50" name="submit" value="" class="bookingFlightbutton">Boeken <span style=" float:right;">></span></button></a>
    </div>
</div>

